package com.example.oracle.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.oracle.entity.SmsTo;
import com.example.oracle.helper.HttpResult;
import com.example.oracle.helper.Page;
import com.example.oracle.service.ISmsToService;
import com.example.oracle.utils.DateUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/smsTo")
public class SmsToController {

	@Autowired
	private ISmsToService stuServiceImpl;

	@RequestMapping("/test")
	public HttpResult test() {
		log.info("测试");
		return HttpResult.success();
	}
	

	@RequestMapping("/generateData")
	public HttpResult generateData(boolean oracle) {
		List<SmsTo> list = new ArrayList<>();
		for (int i = 1530*10000; i < 1730*10000; i++) {
			SmsTo to = new SmsTo();
			to.setId((long)i);
			to.setSmslogid((long)i+2000);
			to.setTophone("1768899394"+i%10);
			to.setReceivedtime(DateUtils.nowTime());
			to.setStatus("unknow");
			to.setTaskid("123456");
			to.setChannelid(23567L);
			to.setChanneltype(12L);
			to.setAmount(20L);
			to.setProvince("广东");
			to.setCity("城市");
			to.setErrormsg(null);
			to.setSendby("API");
			to.setBillingpackageid(null);
			to.setRebateamount(null);
			to.setIsnewbilling(1L);
			to.setChannelname("通道");
			to.setContent("【蜜汁直播】您本次登录验证码为："+i+"，如非本人操作，请忽略此短信。");
			list.add(to);
		}
		log.info("已生成数据{}条", list.size());
		long start = System.currentTimeMillis();
		if (oracle) {
			log.info("oracle");
			this.stuServiceImpl.batchAddOracle(list);
		}else {
			log.info("mysql");
			this.stuServiceImpl.batchAddMysql(list);
		}
		log.info("批量插入{}条：共计耗时{}毫秒", list.size(), System.currentTimeMillis()-start);
		return HttpResult.success();
	}
	
	@RequestMapping("/getPage")
	public HttpResult getPage(Page page, SmsTo to, boolean oracle) {
		page.initPagingData(SmsTo.class);
		List<SmsTo> list = this.stuServiceImpl.getPage(oracle, to);
		return new HttpResult(page.setResult(list));
	}
}
